<?php
/*
 * Created on Feb 5, 2009
 * @author: ANH
 * @PARAM rtype is rootType: example: caves is type then attraction is rtype
 * @filesource: modules/product/controllers/PlaceController.php
 */
class Product_AjaxController extends Clu_Controller_Action_Master
{
	public function init()
	{
		$this->m = new product_Model_Product();
		parent::init();
	}
	
    public function listAction() 
    {
    	$data = $this->_request->getParams();
        if($this->_request->isXmlHttpRequest())
		{	
			$ret = array();
			if($this->m->insertRaw($data, false))
			{
			    $ret['success'] =  true;
				$this->_helper->json->sendJson($ret);
			}
			else
			{
				$ret['success'] =  false;
				$ret['errorMessage'] = "DB error";
				$this->_helper->json->sendJson($ret);
			}
		}
    }
    
    
	public function deleteProductAction()
	{
		$sess = new Zend_Session_Namespace(CLU_NS);
    	$id = $this->_request->getParam('id');
    	if($this->_request->isXmlHttpRequest())
		{
			$db = $this->db;
    	    $ret = array();
    	    //check permission
		    if (strpos ($sess->userPermissions, 'administer product') === false)
			{
				$ret['success'] = false;
				$ret['message'] = t(414);
				$this->_helper->json->sendJson($ret);
				exit();
			}
            if ($this->m->deleteByPrimary($id, true))
            	$ret['success'] = true;
            else
            	$ret['success'] = false;
            	 
			$this->_helper->json->sendJson($ret);
		}
	}
	
    
}
?>
